Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

297
Visualizações
Since printf of a string works with an address in input, why printf does not accept just "argv"
int main(int argc, char **argv){
    printf("argv: %s\n",argv); // does not work and prints random stuff
    printf("*argv: %s\n",*argv); // works and prints ".a.out"

}

I test with:

./a.out nop

My confusion is this:

"argv" variable in the second line has the address of the first char of "./a.out".

"*argv" variable in third line is the first char of "./a.out".

So why printf("argv: %s\n",argv); to only print "./a.out" does not work?

I know that it's wrong, but I don't know why.

enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

argv is a pointer to a pointer. It means it "points" to addresses, not directly to characters.

So at address argv, other addresses are stored, not strings. If you want to access the first string, you have to use the address of it, which is either *argv or argv[0].

I don't know if it's clear enough, don't hesitate to ask for more clarifications.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda